package com.xunshibao.tutor.concern;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xunshibao.tutor.po.TutorDate;
import com.xunshibao.tutor.po.TutorDate.Status;

@Service
public class ConcernServiceImpl {
	@Autowired
	private ConcernDaoImpl dao;
	
	public int addConern(Long infoId, Long userId) {
		TutorDate date = dao.getTutorDate(infoId, userId);
		Date now = new Date();
		if(date == null) {
			date = new TutorDate();
			date.setStatus(TutorDate.Status.ENABLE.value());
			date.setDt(now);
			date.setTid(infoId);
			date.setUid(userId);
			return dao.save(date);
		} else {
			return dao.update(new String[]{"status","dt"}, new Object[]{Status.ENABLE.value(),now, infoId, userId}, "tid=? and uid=?");
		}
	}
	
	public int cancelConern(Long infoId, Long userId) {
		return dao.update(new String[]{"status"}, new Object[]{0, infoId, userId}, "tid=? and uid=?");
	}
	
	public boolean isConcerned(Long infoId, Long userId) {
		return dao.isConcerned(infoId, userId);
	}
	
	public List<TutorDate> getMyConerns(Long userId) {
		return null;
	}
	
	public List<TutorDate> getMyConcernsOfInfo(Long userId, Long infoId) {
		return null;
	}
}
